package com.jiandaoshou.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jiandaoshou.R;
import com.jiandaoshou.entry.DingDanDetailEntry;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2016/12/7.
 */

public class DingDanAdapter extends BaseAdapter {
    private Context context;
    private List<DingDanDetailEntry> mDatas;
    private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm");

    public DingDanAdapter(Context context, List<DingDanDetailEntry> mDatas) {
        this.context = context;
        this.mDatas = mDatas;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int i) {
        return mDatas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_order_msg, null, false);
            holder=new ViewHolder();
            view.setTag(holder);
        } else {
            holder= (ViewHolder) view.getTag();
        }
        holder.Tv_name= (TextView) view.findViewById(R.id.tv_name);
        holder.Tv_time= (TextView) view.findViewById(R.id.tv_time);
        holder.Tv_type= (TextView) view.findViewById(R.id.tv_pay_type);


        holder.Tv_name.setText(mDatas.get(position).getStrShopSonName()+"完成了一个订单消息");
        if (mDatas.get(position).getStrPaymentMode().equals(String.valueOf(1))) {
            holder.Tv_type.setText("微信支付");
        } else if (mDatas.get(position).getStrPaymentMode().equals(String.valueOf(2))) {
            holder.Tv_type.setText("支付宝支付");
        }

        try {
            Date date = format.parse(mDatas.get(position).getDtCreateTime());
            holder.Tv_time.setText(format1.format(date));
        } catch (Exception e) {
            holder.Tv_time.setText(mDatas.get(position).getDtCreateTime());
        }


        return view;
    }

    public class ViewHolder {
        private TextView Tv_name;
        private TextView Tv_time;
        private TextView Tv_type;
    }
}
